package util;

import java.text.*;
import java.util.*;
import bll.Enums;

public class StringUtil {

	private static SimpleDateFormat dateFormat = new SimpleDateFormat(ConfigUtil.dateFormat());

	private static SimpleDateFormat timeFormat = new SimpleDateFormat(ConfigUtil.timeFormat());

	private static SimpleDateFormat dateTimeFormat = new SimpleDateFormat(ConfigUtil.dateTimeFormat());

	private static SimpleDateFormat visualDateTimeFormat = new SimpleDateFormat(ConfigUtil.visualDateTimeFormat());

	private static DecimalFormat decimalFormat = new DecimalFormat(ConfigUtil.numericFormat());

	public static String toDateString(Date date) {
		if (date != null) {
			String str = dateFormat.format(date);
			return str;
		}
		return "";
	}

	public static String toDateTimeString(Date date) {
		if (date != null) {
			String str = dateTimeFormat.format(date);
			return str;
		} else {
			return "";
		}
	}

	public static String toVisualDateTimeString(Date date) {
		if (date != null) {
			String str = visualDateTimeFormat.format(date);
			return str;
		} else {
			return "";
		}
	}

	public static String toTimeString(Date date) {
		if (date != null) {
			String str = timeFormat.format(date);
			return str;
		}

		return "";
	}

	// public static String toNumericString(Double number) {
	// String str = decimalFormat.format(number);
	// return str;
	// }

	public static String toString(double number) {
		String res = decimalFormat.format(number);
		return res;
	}

	public static String toString(double number, int noOfDecimal) {
		DecimalFormat decimalFormat = new DecimalFormat(ConfigUtil.numericFormat(noOfDecimal));
		String res = decimalFormat.format(number);
		return res;
	}

	public static String getProjectStatus(int status) {
		for (Enums.ProjectStatus s : Enums.ProjectStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	public static String getPhaseStatus(int status) {
		for (Enums.PhaseStatus s : Enums.PhaseStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	// Dat added getChecklistItemStatus
	public static String getChecklistItemStatus(int status) {
		for (Enums.ChecklistItemStatus s : Enums.ChecklistItemStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	public static String getAgendaItemStatus(int status) {
		for (Enums.AgendaItemStatus s : Enums.AgendaItemStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	public static String getAgendaStatus(int status) {
		for (Enums.AgendaStatus s : Enums.AgendaStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	public static String getQuotationStatus(int status) {
		for (Enums.QuotationStatus s : Enums.QuotationStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	public static String getQuotationItemStatus(int status) {
		for (Enums.QuotationItemStatus s : Enums.QuotationItemStatus.values()) {
			if (s.getId() == status) {
				return s.getName();
			}
		}
		return "";
	}

	public static String displayStringArray(String[] values, String sep) {
		StringBuilder sb = new StringBuilder();
		for (String val : values) {
			if (val != null && !val.isEmpty()) {
				if (sb.length() > 0) {
					sb.append(sep);
				}
				sb.append(val);
			}
		}
		return sb.toString();
	}

	public static int compareStrings(String source, String dest) {
		String index1 = "";
		if (source != null) {
			index1 = source;
		}
		String index2 = "";
		if (dest != null) {
			index2 = dest;
		}
		int res = index1.compareTo(index2);
		return res;
	}

	public static String getFirstItemText() {
		return "-------------";
	}

	public static String concat(String srcStr, String addedStr, String sep) {
		String res = "";

		if (srcStr != null) {
			res = srcStr;
		}

		if (addedStr != null && !addedStr.isEmpty()) {
			if (!res.isEmpty()) {
				res = res + sep;
			}
			res = res + addedStr;
		}

		return res;
	}

}
